# 断言工具模块
def json_assertion(response_json, expected):
    """
    响应结果为json形式的断言，用于断言实际响应和预期结果是否匹配。

    :param response_json: 实际的响应
    :param expected: 预期的结果，字典格式，包含期望的字段和值,case_param["expected"]是从用例参数化后yaml文件中expected获取的
    """
    for key, expected_value in expected.items():
        actual_value = response_json.get(key)

        # 处理 "not None" 类型的断言
        if expected_value == "not None":
            assert actual_value is not None, f"Expected {key} to be not None, but got None"

        # 检查部分匹配情况
        elif isinstance(expected_value, str) and expected_value in actual_value:
            assert expected_value in actual_value, f"Expected '{expected_value}' to be in '{actual_value}'"

        # 完全相等的情况
        else:
            assert actual_value == expected_value, f"Expected {key} to be '{expected_value}', but got '{actual_value}'"
